# Contributor: Matthias Ahouansou <matthias@ahouansou.cz>
# Contributor: fossdd <fossdd@pwned.life>
# Maintainer: Matthias Ahouansou <matthias@ahouansou.cz>
pkgname=mautrix-slack
pkgver=0.1.2
pkgrel=0
pkgdesc="Matrix-Slack puppeting bridge"
url="https://go.mau.fi/mautrix-slack/"
arch="all"
license="AGPL-3.0-or-later"
makedepends="go olm-dev sqlite-dev"
install="$pkgname.pre-install $pkgname.post-upgrade"
subpackages="$pkgname-openrc $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mautrix/slack/archive/v$pkgver.tar.gz
	mautrix-slack.initd
	mautrix-slack.confd
	"
builddir="$srcdir/slack-$pkgver"
options="net"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"

	go build \
		-ldflags "-X main.Tag=$pkgver -X 'main.BuildTime=$(date -d @"$SOURCE_DATE_EPOCH" '+%b %_d %Y, %H:%M:%S')'" \
		./cmd/mautrix-slack

	./mautrix-slack -e
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 mautrix-slack \
		-t "$pkgdir"/usr/bin/
	install -Dm644 config.yaml \
		-t "$pkgdir"/etc/mautrix-slack/

	install -Dm755 "$srcdir"/mautrix-slack.initd \
		"$pkgdir"/etc/init.d/mautrix-slack
	install -Dm644 "$srcdir"/mautrix-slack.confd \
		"$pkgdir"/etc/conf.d/mautrix-slack

	install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
}

sha512sums="
da390af11437b72e9493d7baccd4ece6301dfb219ecd925f22773a008ce20ad8f2032ec0b021fbc7ee9cec5f060b1045072d0c151348d624ef91d484f6c5c7a9  mautrix-slack-0.1.2.tar.gz
d27fbc6c7ebe9d42eb8226e035649239e6a3e9fbdea21fd9930666da68be375df577fdf9fd6989152e3bee76c924cf77119c57056aff6def84408c4548e8c42a  mautrix-slack.initd
cda8cd828fa1e4e4c302adc79a51d9af99fb428a81639691afefad6b575f6d2ac75730ea2cc455be514fe65a9836bdeb530a86b553c34a47e4a56796ce843fe1  mautrix-slack.confd
"
